package cn.legend.travel.destination.main.dao.search;


import cn.legend.travel.destination.main.pojo.vo.DistrictVO;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.annotations.Query;
import org.springframework.data.elasticsearch.core.SearchPage;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;


@Repository
public interface DestinationElasticsearchRepository
        extends ElasticsearchRepository<DistrictVO, Long> {

    @Query("{\n" +
            "    \"bool\": {\n" +
            "      \"should\": [\n" +
            "        {\n" +
            "          \"match\": {\n" +
            "            \"name\": \"?0\"\n" +
            "          }\n" +
            "        }\n" +
            "      ]\n" +
            "    }\n" +
            "  }")
    SearchPage<DistrictVO> customSearch(String keyword, Pageable pageable);

    @Query("{\n" +
            "    \"bool\": {\n" +
            "      \"must\": [\n" +
            "        {\n" +
            "          \"match_all\": {}\n" +
            "        }\n" +
            "      ],\n" +
            "      \"filter\": [\n" +
            "        {\n" +
            "          \"geo_distance\": {\n" +
            "            \"distance\": \"?0\",\n" +
            "            \"location\": \"?1\"\n" +
            "          }\n" +
            "        }\n" +
            "      ]\n" +
            "    }\n" +
            "  }\n")
    SearchPage<DistrictVO> customSearch(String distance, String location, Pageable pageable);

}
